﻿namespace ConsoleApp1.advance;

public class MyGenericArray<T>{
    private T[] array;
    public MyGenericArray(int size){
        array = new T[size + 1];
    }
    public T getItem(int index){
        return array[index];
    }
    public void setItem(int index, T value){
        array[index] = value;
    }
}

class Tester{
    public static void TestMain(){
        // 声明一个整型数组
        MyGenericArray<int> intArray = new MyGenericArray<int>(5);
        // 设置值
        for (int c = 0; c < 5; c++){
            intArray.setItem(c, c * 5);
        }             // 获取值
        for (int c = 0; c < 5; c++){
            Console.Write(intArray.getItem(c) + " ");
        }
        Console.WriteLine();             // 声明一个字符数组
        MyGenericArray<char> charArray = new MyGenericArray<char>(5);
        // 设置值
        for (int c = 0; c < 5; c++){
            charArray.setItem(c, (char)(c + 97));
        }             // 获取值
        for (int c = 0; c < 5; c++){
            Console.Write(charArray.getItem(c) + " ");
        }
        Console.WriteLine();
        Console.ReadKey();
    }
}